<?php
declare (strict_types=1);

namespace app\admin\controller;

use think\App;
use app\common\builder\TableBuilder;
use app\common\builder\TableFront;

class ProductService extends Base
{

    //主键
    protected $pk = 'id';

    //主模型
    protected $model = '\app\common\model\ProductService';

    public function index()
    {
        return $this->setTable();
    }

    //自动构建table,按需修改
    public function setTable()
    {
        $tableFront = TableFront::getInstance()
            ->addRow(['type' => 'checkbox', 'fixed' => 'left', 'field' => '', 'title' => '全选'])
            ->addRow(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addRow(['field' => 'title', 'title' => '名称', 'modify' => 'add|edit', 'format' => 'input'])
            ->addRow(['field' => 'explain', 'title' => '说明', 'modify' => 'add|edit', 'format' => 'input'])
            ->addRow(['field' => 'create_time', 'title' => '创建时间'])
            ->addRow(['field' => 'update_time', 'title' => '更新时间'])
            ->addRow(['field' => 'status', 'title' => '状态', 'templet' => '#status', 'width' => 120, 'unresize' => true])
            ->addRow(['fixed' => 'right', 'align' => 'center', 'toolbar' => '#barDemo', 'title' => '操作', 'width' => 200]);

        return TableBuilder::getInstance()
            ->addColumns($tableFront)
            ->addRightButtons(['edit' => ['width' => 700, 'height' => 300], 'delete'])
            ->addTopButtons(['add' => ['width' => 700, 'height' => 300], 'deleteAll'])
            ->setSearch($this->setSearch())
            ->addSwitchTool([['name' => 'status', 'pk' => 'id', 'text' => '开启|关闭']])
            ->fetch();
    }

    //自动构建Search，按需修改
    public function setSearch()
    {
        return TableFront::getInstance()
            ->setSearch(['title__explain', '名称/说明', 'input', '', '', '', 'like']);
    }
}
